package com.beiding.my.bemapping;

import com.beiding.my.dtmapping.DtTypeMapper;
import com.beiding.my.dtmapping.DtTypeMapperHolder;
import org.springframework.stereotype.Component;

@Component
public class StaticQuoteHolder {

    private static DtTypeMapperHolder beTypeMapperHolder;

    public StaticQuoteHolder(DtTypeMapperHolder beTypeMapperHolder) {
        StaticQuoteHolder.beTypeMapperHolder = beTypeMapperHolder;
    }

    public static QuoteDetails createQuoteDetails(Class holderBeType, Class targetBeType, String quoteName) {
        DtTypeMapper holderMapper = beTypeMapperHolder.getMapper(holderBeType);
        DtTypeMapper targetMapper = beTypeMapperHolder.getMapper(targetBeType);
        DtTypeMapper quoteMapper = beTypeMapperHolder.getQuoteMapper(targetBeType);

        QuoteDetails quoteDetails = new QuoteDetails();
        quoteDetails.holderTableName = holderMapper.getTableName();
        quoteDetails.holderIdColName = holderMapper.getFieldByName("id").getColName();
        quoteDetails.targetTableName = targetMapper.getTableName();
        quoteDetails.targetIdColName = targetMapper.getFieldByName("id").getColName();
        quoteDetails.quoteTableName = quoteMapper.getTableName();
        quoteDetails.holderFieldColName = quoteMapper.getFieldByName("_" + holderMapper.getName() + "_" + quoteName).getColName();
        quoteDetails.selfFieldColName = quoteMapper.getFieldByName("self").getColName();
        return quoteDetails;
    }

}
